package com.cwvs.cat.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.cwvs.cat.R;
import com.cwvs.cat.bean.MyFriend;
import com.cwvs.cat.net.Port;

public class MyFriendListAdapter extends BaseAdapter {

	private Activity mContent;
	private LayoutInflater inflater;
	private List<MyFriend> list_content;
	private FinalBitmap fb ; 
	public MyFriendListAdapter() {
		// TODO Auto-generated constructor stub
	}

	public MyFriendListAdapter(Activity ac, List<MyFriend> list) {
		// TODO Auto-generated constructor stub
		this.mContent = ac;
		inflater = LayoutInflater.from(ac);
		this.list_content = list;
		fb = FinalBitmap.create(ac);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list_content.size();
	}

	@Override
	public Object getItem(int postion) {
		// TODO Auto-generated method stub
		return list_content.get(postion);
	}

	@Override
	public long getItemId(int postion) {
		// TODO Auto-generated method stub
		return postion;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_list_my_friend,
					null);
			viewHolder = new ViewHolder();
			viewHolder.mtxt_my_friend_name = (TextView) convertView
					.findViewById(R.id.mtxt_my_friend_name);
			viewHolder.mtxt_active_sign = (TextView) convertView
					.findViewById(R.id.mtxt_active_sign);
			viewHolder.head = (ImageView) convertView
					.findViewById(R.id.head);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.mtxt_my_friend_name.setText(list_content.get(position).nickname);
		viewHolder.mtxt_active_sign.setText(list_content.get(position).sign);
		
		if (!list_content.get(position).avatar.equals("")&&!list_content.get(position).avatar.equals("null")) {
			if (list_content.get(position).avatar.contains("http")) {
				fb.display(viewHolder.head,list_content.get(position).avatar);
			}else {
				fb.display(viewHolder.head, Port.getImg+list_content.get(position).avatar);
			}
		}
		
		return convertView;
	}

	class ViewHolder {
		TextView mtxt_my_friend_name,mtxt_active_sign;
		ImageView head;
	}

}